import java.awt.event.*;
import javax.swing.*;

public class KeyboardConnection
{
    Fenster f;

    public KeyboardConnection (Fenster f) {

        this.f = f;

        Action action = new AbstractAction() {
                public void actionPerformed(ActionEvent e) {
                    System.out.println("Herr Rau verbrennt die Gegner mit heißem Kaffee!!!");
                    cheat();
                }
            };            
        Action action1 = new AbstractAction() {
                public void actionPerformed(ActionEvent e) {
                    System.out.println("a");
                }
            };            
        Action action2 = new AbstractAction() {
                public void actionPerformed(ActionEvent e) {
                    System.out.println("s");
                }
            };            
        Action action3 = new AbstractAction() {
                public void actionPerformed(ActionEvent e) {
                    System.out.println("d");
                }
            };            
        Action action4 = new AbstractAction() {
                public void actionPerformed(ActionEvent e) {
                    System.out.println("w");
                }
            };      
        Action action5 = new AbstractAction() {
                public void actionPerformed(ActionEvent e) {
                    System.out.println("h");
                }
            };                            
        Action action6 = new AbstractAction() {
                public void actionPerformed(ActionEvent e) {
                    System.out.println("e");
                }
            };
        Action action7 = new AbstractAction() {
                public void actionPerformed(ActionEvent e) {
                    System.out.println("r");
                }
            };
        Action action8 = new AbstractAction() {
                public void actionPerformed(ActionEvent e) {
                    System.out.println("u");
                }
            };   
        Action action9 = new AbstractAction() {
                public void actionPerformed(ActionEvent e) {
                    System.out.println("Cheat aktiviert!");
                }
            };  

        //keyStroke ermitteln, Version 1
        String keyStrokeAndKey = "control shift Z";
        KeyStroke keyStroke = KeyStroke.getKeyStroke(keyStrokeAndKey);
        String keyStrokeAndKey1 = "A";
        KeyStroke keyStroke1 = KeyStroke.getKeyStroke(keyStrokeAndKey1);
        String keyStrokeAndKey2 = "S";
        KeyStroke keyStroke2 = KeyStroke.getKeyStroke(keyStrokeAndKey2);
        String keyStrokeAndKey3 = "D";
        KeyStroke keyStroke3 = KeyStroke.getKeyStroke(keyStrokeAndKey3);
        String keyStrokeAndKey4 = "W";
        KeyStroke keyStroke4 = KeyStroke.getKeyStroke(keyStrokeAndKey4);
        String keyStrokeAndKey5 = "H";
        KeyStroke keyStroke5 = KeyStroke.getKeyStroke(keyStrokeAndKey5);
        String keyStrokeAndKey6 = "E";
        KeyStroke keyStroke6 = KeyStroke.getKeyStroke(keyStrokeAndKey6);
        String keyStrokeAndKey7 = "R";
        KeyStroke keyStroke7 = KeyStroke.getKeyStroke(keyStrokeAndKey7);
        String keyStrokeAndKey8 = "U";
        KeyStroke keyStroke8 = KeyStroke.getKeyStroke(keyStrokeAndKey8);
        String keyStrokeAndKey9 = "F1";
        KeyStroke keyStroke9 = KeyStroke.getKeyStroke(keyStrokeAndKey9);
        //keyStroke ermitteln, Version 2
        //keyStroke = KeyStroke.getKeyStroke("ENTER");

        //KeyStroke einem JComponent hinzufuegen
        //eingabefeld.getInputMap().put(keyStroke, keyStrokeAndKey);
        //eingabefeld.getActionMap().put(keyStrokeAndKey, action);

        //KeyStroke allen Komponenten hinzufuegen
        f.getRootPane().getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(keyStroke, keyStrokeAndKey);
        f.getRootPane().getActionMap().put(keyStrokeAndKey, action);

        f.getRootPane().getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(keyStroke1, keyStrokeAndKey1);
        f.getRootPane().getActionMap().put(keyStrokeAndKey1, action1);

        f.getRootPane().getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(keyStroke2, keyStrokeAndKey2);
        f.getRootPane().getActionMap().put(keyStrokeAndKey2, action2);

        f.getRootPane().getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(keyStroke3, keyStrokeAndKey3);
        f.getRootPane().getActionMap().put(keyStrokeAndKey3, action3);

        f.getRootPane().getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(keyStroke4, keyStrokeAndKey4);
        f.getRootPane().getActionMap().put(keyStrokeAndKey4, action4);

        f.getRootPane().getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(keyStroke5, keyStrokeAndKey5);
        f.getRootPane().getActionMap().put(keyStrokeAndKey5, action5);

        f.getRootPane().getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(keyStroke6, keyStrokeAndKey6);
        f.getRootPane().getActionMap().put(keyStrokeAndKey6, action6);

        f.getRootPane().getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(keyStroke7, keyStrokeAndKey7);
        f.getRootPane().getActionMap().put(keyStrokeAndKey7, action7);

        f.getRootPane().getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(keyStroke8, keyStrokeAndKey8);
        f.getRootPane().getActionMap().put(keyStrokeAndKey8, action8);

        f.getRootPane().getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(keyStroke9, keyStrokeAndKey9);
        f.getRootPane().getActionMap().put(keyStrokeAndKey9, action9);

    }

    void cheat()
    {
        f.view.controller.cheat(0);
    }
}
